import { LinkedList } from './03.实现linkedList方法2';

const linkedList = new LinkedList<string>();
linkedList.append('aaa');
linkedList.append('bbb');
linkedList.append('ccc');
linkedList.append('ddd');

linkedList.traverse();

console.log('----insert----');

linkedList.insert('abc', 0);
linkedList.traverse();

linkedList.insert('aaaa', 1);
linkedList.insert('aa', 2);
linkedList.traverse();

console.log('-----测试insert的返回值---');
console.log(linkedList.length);
console.log(linkedList.insert('-2', -2));
console.log(linkedList.insert('7777', 7));
console.log(linkedList.insert('888', 8));
linkedList.traverse();

console.log('----removeAt----');

console.log('删除 pos 0:', linkedList.removeAt(0));
linkedList.traverse();

console.log('删除 pos 0:', linkedList.removeAt(0));
linkedList.traverse();

console.log('删除 pos 2:', linkedList.removeAt(2));
linkedList.traverse();

console.log('----get-----');
console.log(linkedList.get(0));
console.log(linkedList.get(2));

console.log('----update-----');
console.log(linkedList.length);
console.log(linkedList.update(0, '黎明'));
linkedList.traverse();
// console.log(linkedList.length);
console.log(linkedList.update(1, '张学友'));
linkedList.traverse();
// console.log(linkedList.length);
console.log(linkedList.update(-2, '刘德华'));
linkedList.traverse();
// console.log(linkedList.length);
console.log(linkedList.update(4, '刘德华'));
linkedList.traverse();
console.log(linkedList.length);

console.log('----indexOf-----');
console.log('刘德华index:', linkedList.indexOf('刘德华'));
console.log('黎明 index:', linkedList.indexOf('黎明'));

console.log('----remove-----');
linkedList.traverse();
console.log('刘德华index:', linkedList.indexOf('刘德华'), linkedList.remove('刘德华'));
console.log('黎明 index:', linkedList.indexOf('黎明'), linkedList.remove('黎明'));
linkedList.traverse();

console.log('----isEmpty----');
console.log(linkedList.isEmpty(), 'length:', linkedList.length);
linkedList.removeAt(0);
linkedList.removeAt(0);
linkedList.removeAt(0);
console.log(linkedList.isEmpty(), 'length:', linkedList.length);
